<?php

namespace app\mobile\controller;

use think\Controller;
use think\Request;
use think\Session;
use think\Route;
use think\Db;

class Person extends Controller
{
    /**
     * 显示页面
     *
     * @return \think\Response
     */
    public function shujia(Request $request)
    {
        $p = $request->post();
        $uid = Session::get('id', 'think');
//        return json($uid);
        if ($uid) {
            $list = db('personshu')->where('uid', $uid)->where('sid', $p['id'])->find();
            if ($list) {
                $info = ['stat' => 4];
            } else {
                $data = [
                    'uid' => $uid,
                    'sid' => $p['id']
                ];
                $res = db('personshu')->insert($data);
                if ($res) {
                    $info = ['stat' => 1];
                } else {
                    $info = ['stat' => 2];
                }
            }
            return json($info);
//

        } else {
            $info = ['stat' => 3];
            return json($info);
        }
    }


    public function showshu()
    {
        $uid=Session::get('id');
        if ($uid){
            $res4=db('category')->where('pid',0)->field('id,cname')->select();
            $data=Db::table('lamp_personshu ps')
                ->where('uid',$uid)
                ->join('lamp_txt t','t.id=ps.sid')
                ->join('lamp_category cate','t.cid=cate.id')
                ->select();
//            dump($data);die;
            return view('person/index',['data4'=>$res4,'data'=>$data]);
        }else{
            return $this->error('请先登录');
        }

//        dump($data);die;

    }
}
